home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / system-config-printer / XmlHelper.pyc (.txt) < prev   
Python Compiled Bytecode  |  2009-10-28  |  3KB  |  68 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import libxml2
  6. from debug import *
  7.  
  8. class XmlHelper(object):
  9.     
  10.     def __init__(self, filename):
  11.         self.group_file_name = None
  12.         self.xml_doc = libxml2.newDoc('1.0')
  13.         self.xml_doc.setRootElement(libxml2.newNode('ospm-groups'))
  14.         self.group_file_name = filename
  15.         if not os.path.exists(self.group_file_name):
  16.             
  17.             try:
  18.                 self.xml_doc.saveFormatFile(self.group_file_name, True)
  19.             nonfatalException()
  20.  
  21.         else:
  22.             
  23.             try:
  24.                 self.xml_doc = libxml2.parseFile(self.group_file_name)
  25.             except:
  26.                 nonfatalException()
  27.  
  28.  
  29.     
  30.     def write(self):
  31.         if self.xml_doc.saveFormatFile(self.group_file_name, True) == -1:
  32.             nonfatalException()
  33.         
  34.  
  35.     
  36.     def __get_non_text_child(self, node):
  37.         child = node.children
  38.         while child and child.isText:
  39.             child = child.next
  40.         return child
  41.  
  42.     
  43.     def __parse_groups(self, key):
  44.         current = self.xml_doc.getRootElement().children
  45.         group_list = []
  46.         while current:
  47.             if current.name == key:
  48.                 group_list.append((current.prop('name'), current))
  49.             
  50.             current = current.next
  51.         return group_list
  52.  
  53.     
  54.     def get_static_groups(self):
  55.         return self._XmlHelper__parse_groups('static-group')
  56.  
  57.     
  58.     def get_search_groups(self):
  59.         return self._XmlHelper__parse_groups('search-group')
  60.  
  61.     
  62.     def add_group(self, group_node):
  63.         self.xml_doc.getRootElement().addChild(group_node)
  64.         self.write()
  65.  
  66.  
  67. xml_helper = XmlHelper(os.path.expanduser('~/.printer-groups.xml'))
  68.